﻿using System;

using RpcClient.Interface;
using RpcClient.Rabbitmq.Interface;
using RpcClient.Rabbitmq.Model;

using Wedonek.Gateway.Modular.Interface;

namespace Wedonek.Gateway.Modular.Service
{
        [RpcClient.Attr.ClassLifetimeAttr(RpcClient.Attr.ClassLifetimeType.单例)]
        internal class RabbitmqDemo : IRabbitmqDemo
        {
                private IRabbitmqService _Rabbitmq;
                private string _Exchange = "Rabbitmq_Demo";
                private ISubscribe _Subscribe = null;
                public RabbitmqDemo(IRabbitmqService service)
                {
                        _Rabbitmq = service;
                        _Subscribe = _Rabbitmq.Subscribe(_Exchange, _SubscribeMsg);
                }
                public void Public()
                {
                        _Rabbitmq.Public("Ok", _Exchange, "Demo_Msg");
                }

                public void Subscribe()
                {
                        _Subscribe.BindRoute("Demo_Queue", "Demo_Msg");
                }

                private void _SubscribeMsg(ISubscribe sub, ISubEventArgs arg)
                {
                        Console.WriteLine("RoutingKey：" + arg.RoutingKey);
                        Console.WriteLine("收到订阅消息：" + arg.GetValue());
                }
                public void Dispose()
                {
                        _Subscribe?.Dispose();
                }

        }
}
